﻿using DHQGHN.DAL.Common;
using DHQGHN.DAL.DAO.DHQG;
using DHQGHN.DAL.Models.DHQG;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DHQGHN.DAL.BO.DHQG
{
    public class NhomDonViBO : BaseBO
    {
        private NhomDonViDAO _dao;

        public const string NHOM_DON_VI_ID = "NHOM_DON_VI_ID";
        public const string TEN_NHOM_DON_VI = "TEN_NHOM_DON_VI";
        public const string GHI_CHU = "GHI_CHU";
        public const string IS_CO_BAN = "IS_CO_BAN";
        public const string IS_CHECKED = "IS_CHECKED";
        public const string RECORD_COUNT = "RECORD_COUNT";
        public NhomDonViBO()
        {
            _dao = new NhomDonViDAO(Common.ConnectionUtil.DHQGHN_CONNECTION_STRING, DEFAULT_MAPPER_TYPE);
        }

        public NhomDonViBO(string connectionString)
        {
            _dao = new NhomDonViDAO(connectionString, DEFAULT_MAPPER_TYPE);
        }

        public DataPage<NhomDonVi> GetListPaging(NhomDonVi model, int pageIndex, int pageSize)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetListPaging(model, pageIndex, pageSize, mapDictionary);
            }
            catch
            {
                throw;
            }
        }

        public NhomDonVi GetById(int id)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetById(id, mapDictionary);
            }
            catch
            {
                throw;
            }
        }

        //phunx1, 20160411: lay danh sach nhom don vi
        public List<NhomDonVi> GetAll()
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetAll(mapDictionary);
            }
            catch
            {
                throw;
            }
        }

        //tra lai nhom don vi theo loại nhom: 0: nhom mo rong, 1: nhom co ban; 2: tat ca
        public List<NhomDonVi> GetNhomDVByType(int intISCoBan)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetNhomDVByType(intISCoBan, mapDictionary);
            }
            catch
            {
                throw;
            }
        }

        //phunx1, 20160627: ham nay chi su dung trong quan ly danh muc nguoi dung Admin
        public List<NhomDonVi> GetNhomDVByType_New(int intISCoBan)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetNhomDVByType_New(intISCoBan, mapDictionary);
            }
            catch
            {
                throw;
            }
        }

        public List<NhomDonVi> GetAllNhomByDonViID(int donViID)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                return _dao.GetAllNhomByDonViID(donViID, mapDictionary);
            }
            catch
            {
                throw;
            }
        }

        public bool Save(NhomDonVi model)
        {
            try
            {
                return _dao.Save(model);
            }
            catch
            {
                throw;
            }
        }

        public bool Delete(int id)
        {
            try
            {
                return _dao.Delete(id);
            }
            catch
            {
                throw;
            }
        }

        private Dictionary<string, string> GetMapDictionary()
        {
            Dictionary<string, string> mapDictionary = new Dictionary<string, string>()
            {
                {NhomDonVi.FIELD_NHOM_DON_VI_ID, NhomDonViBO.NHOM_DON_VI_ID},
                {NhomDonVi.FIELD_TEN_NHOM_DON_VI, NhomDonViBO.TEN_NHOM_DON_VI},
                {NhomDonVi.FIELD_GHI_CHU,NhomDonViBO.GHI_CHU},
                {NhomDonVi.FIELD_IS_CO_BAN,NhomDonViBO.IS_CO_BAN},
                {NhomDonVi.FIELD_IS_CHECKED,NhomDonViBO.IS_CHECKED},
                {NhomDonVi.FIELD_RECORD_COUNT,NhomDonViBO.RECORD_COUNT},
            };

            return mapDictionary;
        }
    }
}
